#ifndef PM_COST_H_INCLUDED
#define PM_COST_H_INCLUDED

#include "pm/dbobject.h"
#include "pm/criteria.h"
#include <wx/datetime.h>

namespace pm
{

/**
 * \class Cost
 */
class Cost : public db::Object
{
	double     m_unitCost;
	double     m_quantity;
	wxString   m_name;
	wxDateTime m_date;
	db::ID     m_idTask;
	
public:
	static const wxString TABLE_NAME;
	
public:
	Cost();
	Cost(wxSQLite3ResultSet& res);

	const wxString& name() const { return m_name; }
	void name(const wxString& name) { m_name = name; }
	
	double unit_cost() const { return m_unitCost; }
	void unit_cost(double c) { m_unitCost = c; }
	
	double quantity() const { return m_quantity; }
	void quantity(double q) { m_quantity = q; }
	
	const wxDateTime& date() const { return m_date; }
	void date(const wxDateTime& date) { m_date = date; }
	
	db::ID id_task() const { return m_idTask; }
	void id_task(db::ID idTask) { m_idTask = idTask; }

	double cost() const { return m_unitCost * m_quantity; }

	// DB
	virtual db::update_value_type prepare_insert(wxSQLite3Database& db);
	virtual db::update_value_type prepare_update(wxSQLite3Database& db);
};

typedef std::list<Cost> ListCost;

/**
 * \class CostInfo
 */
class CostInfo : public Cost
{
	db::ID   m_idProject;
	wxString m_taskName;

public:
	static const wxString TABLE_NAME;

public:	
	CostInfo();
	CostInfo(wxSQLite3ResultSet& res);
	
	db::ID id_project() const { return m_idProject; }
	const wxString& task_name() const { return m_taskName; }
};

/**
 * \class GetCostsByProject
 */
struct GetCostsByProject : public ICriteriaForEach<CostInfo>
{
	db::ID       m_idProject;
	
	GetCostsByProject(db::ID id_project);
	
	virtual wxSQLite3Statement prepare(wxSQLite3Database& db);
};

} // namespace pm

#endif // PM_COST_H_INCLUDED
